<admintpl file="header" />
</head>
<style>
    .input_edit{
        width:120px;}
</style>
<body>
<div class="wrap js-check-wrap">
    <div class="wrap js-check-wrap">
        <ul class="nav nav-tabs">
            <li class="active"><a href="{:U('NewsSet/defaultIndex')}">栏目列表</a></li>
            <if condition="$status eq 1"><li><a href="{:U('NewsSet/add')}">添加栏目</a></li></if>
        </ul>
        <form class="form-horizontal js-ajax-form" action="{:U('NewsSet/defaultIndex')}" method="post">
            <table class="table table-hover table-bordered table-list">
                <if condition="$status eq 1">
                <thead>
                <tr>
                    <th width="80">序号</th>
                    <th width="220">栏目名称</th>
                    <th width="220">权重</th>
                    <th width="700">管理员</th>
                    <th>操作</th>
                </tr>
                </thead>
                <!--显示全部栏目列表 可操作-->
                    <foreach name="data" item="vo">
                        <p style="display: none;" id="dis_column_name">{$vo.name}</p>
                        <p style="display: none;" id="dis_weight">{$vo.weight}</p>
                        <p style="display: none;" id="dis_username">{$vo.user_login}</p>
                        <tr>
                            <td>
                                {$vo.column_id}
                            </td>
                            <td id="column_id">
                                <input name="{$vo.column_id}" disabled="disabled" type="text" size="3" value="{$vo.name}" id="input-column-{$vo.column_id}" class="input_edit">
                                <a style="float: right;" id="edit_column-{$vo.column_id}" href="javascript:void(0)" onclick="edit_column('column_id','{$vo.column_id}')" class="edit_sub">修改</a>
                            </td>
                            <td>
                                <input name="{$vo.weight}" disabled="disabled" type="text" size="3" value="{$vo.weight}" id="input-weight-{$vo.column_id}" class="input_edit">
                                <a style="float: right;"  id="edit_weight-{$vo.column_id}" href="javascript:void(0)" onclick="edit_column('weight','{$vo.column_id}')" class="edit_sub">修改</a>
                            </td>
                            <td style="word-wrap:break-word;word-break:break-all;">
                                <if condition="$vo.type eq 2">
                                    {$name}
                                <else/>
                                    {$vo.usernames}
                                </if>


                                <if condition="$vo.type neq 2">
                                    <a style="float:right;"  class="btn btn-primary"  onclick="edit_admin('{$vo.column_id}','{$vo.admin_ids}','{$vo.usernames}')">修改</a>
                                </if>
                            </td>
                            <td>
                                <a href='{:U("Admin/NewsSet/Delete",array("id"=>$vo["column_id"]))}' class="js-ajax-delete" data-msg="确定要删除此栏目吗？">删除</a>
                                <if condition="$vo.type neq 2">
                                    <a href="{:U('News/index',array('column_id'=>$vo['column_id']))}" style="margin-left: 20px;">进入文章列表</a>

                                    <a onclick="edit_liverole('{$vo.column_id}','{$vo.admin_ids}','{$vo.usernames}','{$vo.live_status}')" style="margin-left: 25px;">直播权限设置</a>
                                </if>

                            </td>
                        </tr>
                    </foreach>
                    <else />
                    <!-- 显示有权限的 可操作栏目 -->
                    <foreach name="data" item="vo">
                        <?php
                        if($vo['column_id']){
                            $column = "column_id";
                            $column_val = $vo['column_id'];
                        }else{
                            $column = "area_id";$column_val = $vo['area_id'];
                        }?>
                        <tr>
                        <td>
                            <a href="{:U('News/index',array($column=>$column_val))}">{$vo.name}</a>
                        </td>
                        </tr>
                    </foreach>
                </if>

            </table>
        </form>
        <div class="pagination">{$page}</div>
    </div>

</div>
<script src="__PUBLIC__/js/common.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<script>
    function edit_admin(column_id,admin_ids,usernames){
        layer.open({
            type: 2,
            //skin: 'layui-layer-lan',
            title: '修改管理员',
            fix: false,
            shadeClose: true,
            maxmin: true,
            area: ['600px', '300px'],
            content: "<?php echo U('Admin/NewsSet/editAdmin')?>"+'&column_id='+column_id+'&admin_ids='+admin_ids+'&usernames='+usernames,
            end: function(){
                location.reload();
            }
        });
    }
    function edit_column(type,column_id){
        var edit_column;
        var column_befor;
        var column;
        var now_input_type;
        var now_edit_type;
        if(type == "column_id"){
            edit_column = $("#edit_column-"+column_id).html();
            column_befor = $("#dis_column_name").html();   //原栏目名
            column  = $("#input-column-"+column_id).val(); //现栏目名
            now_input_type = $("#input-column-" + column_id); //栏目 ID
            now_edit_type  = $("#edit_column-" + column_id);  //修改 按钮ID
        } else if(type == "weight"){
            edit_column = $("#edit_weight-" +column_id).html();
            column_befor = $("#dis_weight").html();        //原权重值
            column  = $("#input-weight-" +column_id).val(); //现权重值
            now_input_type = $("#input-weight-" + column_id); //权重 ID
            now_edit_type  = $("#edit_weight-" + column_id);  //修改 按钮ID
        }
        if(edit_column == "修改"){
            //处理 同时存在多个input编辑问题
            $(".input_edit").attr("disabled", "disabled");
            $(".edit_sub").html("修改");

            now_input_type.removeAttr("disabled");
            now_edit_type.html("确认");
        }else{
            if(column_befor == column){
                now_input_type.attr("disabled", "disabled");
                now_edit_type.html("修改");
            }else {
                if(type == "column_id"){
                    $.ajax({
                        type:"post",
                        async:false,
                        url:"{:U('Admin/Movement/filter_words')}",
                        data:'name='+column,
                        dataType:"text",
                        success:function(data){
                            if(data){
                                if(confirm('您编辑的内容涉及敏感词'+data+'是否继续操作')){
                                    flag= true;
                                    return true;
                                }else{
                                    flag= false;
                                    return false;
                                }
                            }else{
                                flag = true;
                                return true;
                            }
                        }
                    });
                    if(flag == false){
                        return false;
                    }
                }
                $.post("{:U('NewsSet/Edit')}", {type: type, id: column_id, val: column},
                    function (result) {
                        if (result == 1) {
                            now_input_type.attr("disabled", "disabled");
                            now_edit_type.html("修改");
                            location.reload();
                        }else{
                            alert("异常!");
                        }
                    }
                );
            }
        }
    };

    function edit_liverole(column_id,admin_ids,usernames,live_status){
        layer.open({
            type: 2,
            //skin: 'layui-layer-lan',
            title: '直播权限设置',
            fix: false,
            shadeClose: true,
            maxmin: true,
            area: ['700px', '300px'],
            content: "<?php echo U('Admin/NewsSet/editliverole')?>"+'&column_id='+column_id+'&admin_ids='+admin_ids+'&usernames='+usernames+'&live_status='+live_status+'&type='+0,
            end: function(){
                location.reload();
            }
        });
    }
</script>

</body>
</html>